<!-- 画廊 -->
{{- $url := .Get 2 -}}
{{- $md5Hash := md5 $url -}}
{{- $md5Short := substr $md5Hash 0 8 -}}
<link href="https://cdn.bootcdn.net/ajax/libs/justifiedGallery/3.8.1/css/justifiedGallery.min.css" rel="stylesheet">
<div id="{{- $md5Short -}}">
</div>
<script type="text/javascript" src="https://cdn.ftls.xyz/static/whispers/assets/js/view-image.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/justifiedGallery/3.8.1/js/jquery.justifiedGallery.min.js"></script>
<script>
    fetch("{{ $url }}")
    .then(response => response.text())
    .then(text => {
        text.trim().split('\n').forEach((imageUrl) => {
        const anchor = document.createElement("a");
        anchor.href = imageUrl;
        anchor.classList.add("gallery-img");

        const img = document.createElement("img");
        img.src = imageUrl + `${imageUrl.includes("?") ? "" : "?image_process=quality,Q_10"}`; // 略缩图 - 使用 CDN 的图像处理
        img.alt = "";
        img.loading = "lazy";

        anchor.appendChild(img);
        document.getElementById("{{- $md5Short -}}").appendChild(anchor);
    });
        $("#{{- $md5Short -}}").justifiedGallery({
            rowHeight: {{ .Get 0 | default 200 }},
        });
        if({{- .Get 1 | default false -}} == true) {
            window.ViewImage && ViewImage.init('.gallery-img');
        }
    });
</script>